package com.ujiuye.util;

public class PackageUtil {
    private int page;
    private int rows;
    private int index;
    private int countRows;
    private int countPage;
    private int prevPage;
    private int nextPage;

    public PackageUtil() {
    }

    public PackageUtil(String page, int rows, int countRows) {
        this.rows = rows;
        this.countRows = countRows;
        init_page(page);
        init_index();
        init_countPage();
        init_prevPage();
        init_nextPage();
    }

    //初始化页码
    private void init_page(String page) {
        if (page == null || "".equals(page)) {
            this.page = 1;
        } else {
            this.page = Integer.parseInt(page);
        }
    }

    //初始化偏移量
    private void init_index() {
        this.index = (this.page - 1) * this.rows;
    }

    //初始化总页数
    private void init_countPage() {
        int mod = this.countRows % this.rows;
        if (mod == 0) {
            this.countPage = this.countRows / this.rows;
        } else {
            this.countPage = this.countRows / this.rows + 1;
        }
    }

    //初始化当前页面的上一页页码
    private void init_prevPage() {
        if (this.page == 1) {
            this.prevPage = 1;
        } else {
            this.prevPage = this.page - 1;
        }
    }

    //初始化当前页面的下一页页码
    private void init_nextPage() {
        if (this.page == countPage) {
            this.nextPage = this.countPage;
        } else {
            this.nextPage = this.page + 1;
        }
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public int getCountRows() {
        return countRows;
    }

    public void setCountRows(int countRows) {
        this.countRows = countRows;
    }

    public int getCountPage() {
        return countPage;
    }

    public void setCountPage(int countPage) {
        this.countPage = countPage;
    }

    public int getPrevPage() {
        return prevPage;
    }

    public void setPrevPage(int prevPage) {
        this.prevPage = prevPage;
    }

    public int getNextPage() {
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }
}
